home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / src / networks / novia_serial.c
C/C++ Source or Header  |  1999-12-06  |  18KB  |  663 lines

  1. #include <exec/types.h>
  2. #include <stdlib.h>
  3. #include <exec/ports.h>
  4. #include <exec/io.h>
  5. #include <exec/tasks.h>
  6. #include <exec/lists.h>
  7. #include <pragma/exec_lib.h>
  8. #include <pragma/dos_lib.h>
  9. #include <pragma/intuition_lib.h>
  10. #include <pragma/gadtools_lib.h>
  11. #include <novia/novia_UserList.h>
  12. #include <novia/novia_PortData.h>
  13. #include <novia/novia_config.h>
  14. #include <novia/novia_vde.h>
  15. #include <novia/novia_mail.h>
  16. #include <novia/novia_subboard.h>
  17. #include <novia/novia_types.h>
  18. #include <novia/novia_misc.h>
  19. #include <novia/novia_message.h>
  20. #include <novia/novia_gui.h>
  21. #include <exec/memory.h>
  22. #include <dos/dos.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <intuition/intuition.h>
  26. #include <rexx/storage.h>
  27. #include <clib/rexxsyslib_protos.h>
  28. #include <novia/novia_funcs.h>
  29. #include <pragma/noviasys_lib.h>
  30.  
  31. //#define DEBUG
  32.  
  33. /* **** NOVIA_MAIN.C IMPORTS **** */
  34.  
  35. extern struct Task *MainTask;
  36. extern struct MsgPort *GUIPort;
  37. extern struct MsgPort *MainGUIPort;
  38. extern struct MsgPort *main_eventport;
  39. extern struct MainPortConfig *mainportconfig;
  40. extern struct List *client_list;
  41.  
  42.  
  43. /* **** PROTOTYPES **** */
  44.  
  45. BOOL SN_Open();
  46. void SN_Close();
  47. BOOL SN_CheckNetworkStatus();
  48. LONG SN_Send(APTR data, ULONG len);
  49. ULONG SN_Recv(char *string, char len, ULONG BreakBitMask);
  50. void SN_HangingUP();
  51. void SN_WaitConnect();
  52.  
  53.  
  54. /* ************************** */
  55.  
  56. #define PORTTYPE_MAIN 1
  57. #define PORTTYPE_CLIENT 0
  58.  
  59.  
  60. BOOL SN_Open()
  61. {
  62.     char error                = FALSE;
  63.  
  64.     struct PortData        *cport;
  65.  
  66.     struct SerialNetwork    *sn = NULL;
  67.  
  68.     if ((cport = (PortData *)FindTask(NULL)->tc_UserData))
  69.     {
  70.         if (!cport->network.isopen)
  71.         {
  72.             if (cport->network.networktype == NETWORKTYPE_SERIAL)
  73.             {
  74.                 if ((cport->network.networkdata = AllocVec(sizeof(SerialNetwork),MEMF_ANY|MEMF_CLEAR)))
  75.                 {
  76.                     sn = cport->network.networkdata;
  77.                     sn->SerWritePort    = CreateMsgPort();
  78.                     sn->SerReadPort    = CreateMsgPort();
  79.                     sn->SerQueryPort    = CreateMsgPort();
  80.                 
  81.                     sn->SerWrite        = NULL;
  82.                     sn->SerRead            = NULL;
  83.                     sn->SerQuery        = NULL;
  84.                 
  85.                     if (sn->SerReadPort && sn->SerWritePort && sn->SerQueryPort)
  86.                     {
  87.                         sn->SerRead        = CreateIORequest(sn->SerReadPort,sizeof(IOExtSer));
  88.                         sn->SerQuery    = CreateIORequest(sn->SerQueryPort,sizeof(IOExtSer));
  89.                         sn->SerWrite    = CreateIORequest(sn->SerWritePort,sizeof(IOExtSer));
  90.                         if (sn->SerWrite && sn->SerWrite && sn->SerQuery)
  91.                         {
  92.                 
  93.                            sn->SerWrite->IOSer.io_Message.mn_ReplyPort = sn->SerWritePort;
  94.                 
  95.                             if (OpenDevice(cport->clientconfig.SerialData.Device_Name,cport->clientconfig.SerialData.Unit,(IORequest *)sn->SerWrite,0))
  96.                             {
  97.                                 ioprintf("can't open serial.device. Device-Errorcode: %d\n",sn->SerWrite->IOSer.io_Error);
  98.                                 error = TRUE;
  99.                             }
  100.                             else
  101.                             {
  102.                                 cport->network.isopen = TRUE;
  103.                 
  104.                                 /*** SET SERIAL PARAMS ***/
  105.                 
  106.                                 sn->SerWrite->io_RBufLen            = 20;                                                        // Größe des Eingangspuffers; ein Vielfaches von 64 Bytes
  107.                                 sn->SerWrite->io_Baud                = cport->clientconfig.SerialData.OnlineBaud;
  108.                                 sn->SerWrite->io_BrkTime            = 100;                                                    // Dauer des Unterbrechungssignals in Microsekunden.
  109.                                 sn->SerWrite->io_ReadLen            = cport->clientconfig.SerialData.DataBits;
  110.                                 sn->SerWrite->io_WriteLen            = cport->clientconfig.SerialData.DataBits;
  111.                                 sn->SerWrite->io_StopBits            = cport->clientconfig.SerialData.StopBits;
  112.                                 sn->SerWrite->io_SerFlags            = SERF_XDISABLED|SERF_7WIRE;
  113.                                 sn->SerWrite->IOSer.io_Command    = SDCMD_SETPARAMS;
  114.                                 DoIO((IORequest *)sn->SerWrite);                                                                // Set parameters
  115.                 
  116.                                 *sn->SerRead = *sn->SerWrite;                                                                // Copy SerWrite in SerRead
  117.                                 sn->SerRead->IOSer.io_Message.mn_ReplyPort  = sn->SerReadPort;                    // change correct port address
  118.                 
  119.                                 *sn->SerQuery = *sn->SerWrite;
  120.                                 sn->SerQuery->IOSer.io_Message.mn_ReplyPort = sn->SerQueryPort;
  121.                 
  122.                                 sn->SerWrite->IOSer.io_Command = CMD_WRITE;
  123.                                 sn->SerWrite->IOSer.io_Flags = IOF_QUICK;
  124.                 
  125.                                 sn->SerWrite->IOSer.io_Data    = "ATZ\r";
  126.                                 sn->SerWrite->IOSer.io_Length  = 4;
  127.                                 sn->SerWrite->IOSer.io_Flags   = IOF_QUICK;
  128.                                 sn->SerWrite->IOSer.io_Command = CMD_WRITE;
  129.                                 DoIO((IORequest *)sn->SerWrite);
  130.                 
  131.                                 sn->SerQuery->IOSer.io_Command = SDCMD_QUERY;
  132.                                 sn->SerQuery->IOSer.io_Data    = (APTR) cport->network.ReadBuf;
  133.                                 sn->SerQuery->IOSer.io_Length  = 0;
  134.                             }
  135.                         }
  136.                         else
  137.                         {
  138.                             ioprintf("can't open serial.device, out of memory.\n");
  139.                             error = TRUE;
  140.                         }
  141.                     }
  142.                     else
  143.                     {
  144.                         ioprintf("can't open serial.device, out of memory.\n");
  145.                         error = TRUE;
  146.                     }
  147.                 }
  148.                 else
  149.                 {
  150.                     ioprintf("internal error, can't find networkdate-structure.\n");
  151.                     error = TRUE;
  152.                 }
  153.             }
  154.             else
  155.             {
  156.                 ioprintf("internal error network is not a serial-device.\n");
  157.                 error = TRUE;
  158.             }
  159.         }
  160.         else
  161.         {
  162.             ioprintf("serial.device is already open.\n");
  163.             error = TRUE;
  164.         }
  165.     }
  166.  
  167.     if (error && sn)
  168.     {
  169.         if (sn->SerWritePort)
  170.         {
  171.             if (sn->SerWrite)
  172.             {
  173.                 DeleteIORequest((IORequest *)sn->SerWrite);
  174.                 sn->SerWrite = NULL;
  175.             }
  176.             DeleteMsgPort(sn->SerWritePort);
  177.             sn->SerWritePort = NULL;
  178.         }
  179.         if (sn->SerReadPort)
  180.         {
  181.             if (sn->SerRead)
  182.             {
  183.                 DeleteIORequest((IORequest *)sn->SerRead);
  184.                 sn->SerRead = NULL;
  185.             }
  186.             DeleteMsgPort(sn->SerReadPort);
  187.             sn->SerReadPort = NULL;
  188.         }
  189.         if (sn->SerQueryPort)
  190.         {
  191.             if (sn->SerQuery)
  192.             {
  193.                 DeleteIORequest((IORequest *)sn->SerQuery);
  194.                 sn->SerQuery = NULL;
  195.             }
  196.             DeleteMsgPort(sn->SerQueryPort);
  197.             sn->SerQueryPort = NULL;
  198.         }
  199.     }
  200.     if (!error)
  201.         return TRUE;
  202. }
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209. void SN_Close()
  210. {
  211.     struct PortData        *cport;
  212.  
  213.     struct SerialNetwork    *sn = NULL;
  214.  
  215.     if (cport = (PortData *)FindTask(NULL)->tc_UserData)
  216.     {
  217.         if (cport->network.networktype == NETWORKTYPE_SERIAL)
  218.         {
  219.             if ((sn = cport->network.networkdata))
  220.             {
  221.                 if (cport->network.isopen)
  222.                 {
  223.                     AbortIO((IORequest *)sn->SerRead);
  224.                     WaitIO((IORequest *)sn->SerRead);
  225.                     sn->SerRead->IOSer.io_Command    =    CMD_READ;
  226.                     sn->SerRead->IOSer.io_Data        =    cport->network.ReadBuf;
  227.                     sn->SerRead->IOSer.io_Length    =    1;
  228.                     while(CheckIO((IORequest *)sn->SerRead))
  229.                     {
  230.                         WaitIO((IORequest *)sn->SerRead);
  231.                         SendIO((IORequest *)sn->SerRead);
  232.                     }
  233.  
  234.                     AbortIO((IORequest *)sn->SerWrite);
  235.                     WaitIO((IORequest *)sn->SerWrite);
  236.  
  237.                     AbortIO((IORequest *)sn->SerQuery);
  238.                     WaitIO((IORequest *)sn->SerQuery);
  239.  
  240.                     CloseDevice((IORequest *)sn->SerWrite);
  241.                 }
  242.  
  243.                 DeleteIORequest((IORequest *)sn->SerWrite);
  244.                 sn->SerWrite=NULL;
  245.  
  246.                 DeleteIORequest((IORequest *)sn->SerRead);
  247.                 sn->SerRead=NULL;
  248.  
  249.                 DeleteIORequest((IORequest *)sn->SerQuery);
  250.                 sn->SerQuery=NULL;
  251.  
  252.                 DeleteMsgPort(sn->SerWritePort);
  253.                 sn->SerWritePort=NULL;
  254.  
  255.                 DeleteMsgPort(sn->SerReadPort);
  256.                 sn->SerReadPort=NULL;
  257.  
  258.                 DeleteMsgPort(sn->SerQueryPort);
  259.                 sn->SerQueryPort=NULL;
  260.  
  261.                 FreeVec(sn);
  262.                 cport->network.networkdata = NULL;
  263.             }
  264.             else
  265.                 ioprintf("internal error: can't find networkdate-structure.\n");
  266.         }
  267.     }
  268.     else
  269.         ioprintf("internal error: can't find PortData-structure.\n");
  270. }
  271.  
  272.  
  273.  
  274. BOOL SN_CheckNetworkStatus()
  275. {
  276.     struct PortData *cport;
  277.     if (cport = (PortData *)FindTask(NULL)->tc_UserData)
  278.     {
  279.         if (cport->network.isopen)
  280.         {
  281.             if (cport->network.networktype == NETWORKTYPE_SERIAL)
  282.             {
  283.                 struct SerialNetwork *sn = cport->network.networkdata;
  284.                 if (!(DoIO((IORequest *)sn->SerQuery)))
  285.                 {
  286.                     if (!(sn->SerQuery->io_Status & (1<<5)))        // Check Carrier
  287.                     {
  288.                         cport->network.online=TRUE;
  289.                     }
  290.                     else
  291.                     {
  292.                         if (cport->network.online)
  293.                         {
  294.                             cport->network.online=FALSE;
  295.                             SendMsg(cport->MainPort,cport,0,MSG_PORT_LOSTCARRIER,NULL);
  296.                         }
  297.                     }
  298.                 }
  299.             }
  300.         }
  301.     }
  302.     return ((BOOL)cport->network.online );
  303. }
  304.  
  305.  
  306. LONG SN_Send(APTR data, ULONG len)
  307. {
  308.     struct    PortData            *cport            = (PortData *)FindTask(NULL)->tc_UserData;
  309.     char                            SerWriteFinish    = FALSE;
  310.     ULONG                         signals            = (1<<cport->TimePort->mp_SigBit);
  311.     struct    SerialNetwork     *sn;
  312.  
  313.     if ((cport = (PortData *)FindTask(NULL)->tc_UserData))
  314.     {
  315.         if (cport->network.isopen)
  316.         {
  317.             if (cport->network.networktype == NETWORKTYPE_SERIAL)
  318.             {
  319.                 if ((sn = cport->network.networkdata))
  320.                 {
  321.                     signals    =    signals | (1<<sn->SerWritePort->mp_SigBit);
  322.                     sn->SerWrite->IOSer.io_Flags        = IOF_QUICK;
  323.                     sn->SerWrite->IOSer.io_Data        = data;
  324.                     sn->SerWrite->IOSer.io_Length        = len;
  325.                       sn->SerWrite->IOSer.io_Command    = CMD_WRITE;
  326.                     SendIO((IORequest *)sn->SerWrite);
  327.  
  328.                     if (!(CheckIO((IORequest *)cport->TimerReq)))
  329.                     {
  330.                         AbortIO((IORequest *)cport->TimerReq);
  331.                         WaitIO((IORequest *)cport->TimerReq);
  332.                     }
  333.     
  334.                     cport->TimerReq->tr_time.tv_secs        = 1;
  335.                     cport->TimerReq->tr_time.tv_micro    = 0;
  336.                     cport->TimerReq->tr_node.io_Command    = TR_ADDREQUEST;
  337.                     SendIO((IORequest *)cport->TimerReq);
  338.     
  339.                     while (SerWriteFinish == FALSE)
  340.                     {
  341.                         if (CheckIO((IORequest *)sn->SerWrite))
  342.                         {
  343.                             WaitIO((IORequest *)sn->SerWrite);            // reply IORequest-Message to serial.device
  344.                             SerWriteFinish = TRUE;
  345.                         }
  346.                         if (CheckIO((IORequest *)cport->TimerReq))
  347.                         {
  348.                             WaitIO((IORequest *)cport->TimerReq);            // first step, reply to timer.device
  349.                             SerWriteFinish = TRUE;
  350.                         }
  351.                         if (SerWriteFinish == NULL )
  352.                         Wait(signals);
  353.                     }
  354.     
  355.                     AbortIO((IORequest *)cport->TimerReq);                /* Abort timerequest */
  356.                     WaitIO((IORequest *)cport->TimerReq);
  357.     
  358.     
  359.                     if (!(CheckIO((IORequest *)sn->SerWrite)))
  360.                         AbortIO((IORequest *)sn->SerWrite);
  361.                     WaitIO((IORequest *)sn->SerWrite);
  362.                     if (!cport->connect_seq)
  363.                         SN_CheckNetworkStatus();
  364.                 }
  365.             }
  366.         }
  367.     }
  368.     return TRUE;
  369. }
  370.  
  371.  
  372. ULONG SN_Recv(char *string, char len, ULONG BreakBitMask)
  373. {
  374.     struct    PortData            *cport            = (PortData *)FindTask(NULL)->tc_UserData;
  375.     char                            SerWriteFinish    = FALSE;
  376.     ULONG                         signals            = (1<<cport->TimePort->mp_SigBit);
  377.     struct    SerialNetwork     *sn;
  378.     ULONG                         result            = 0;
  379.  
  380.     if ((cport = (PortData *)FindTask(NULL)->tc_UserData))
  381.     {
  382.         if (cport->network.isopen)
  383.         {
  384.             if (cport->network.networktype == NETWORKTYPE_SERIAL)
  385.             {
  386.                 if ((sn = cport->network.networkdata))
  387.                 {
  388.                     ULONG sb_SerReadPort=1<<sn->SerReadPort->mp_SigBit;
  389.                     BOOL quit = FALSE;
  390.  
  391.                     AbortIO((IORequest *)sn->SerRead);
  392.                     WaitIO((IORequest *)sn->SerRead);
  393.  
  394.                     sn->SerRead->IOSer.io_Data=(APTR)cport->network.ReadBuf;
  395.                     sn->SerRead->IOSer.io_Length=1;
  396.                       sn->SerRead->IOSer.io_Command = CMD_READ;
  397.  
  398.                       SendIO((IORequest *)sn->SerRead);
  399.                     sn->SerReadSend=TRUE;
  400.  
  401.                     *string=0;
  402.                     while (!cport->ProgramClose && ((cport->network.online)|cport->connect_seq) && !quit)
  403.                     {
  404.                         result=WaitSig(sb_SerReadPort | BreakBitMask);
  405.                         if (sb_SerReadPort & result)
  406.                         {
  407.                             if (cport->network.isopen && sn->SerRead && sn->SerReadSend)
  408.                             {
  409.                                 if (CheckIO((IORequest *)sn->SerRead))
  410.                                 {
  411.                                     WaitIO((IORequest *)sn->SerRead);
  412.                                    if (sn->SerRead->IOSer.io_Actual > 0)
  413.                                     {
  414.                                         *string=*((char *)sn->SerRead->IOSer.io_Data);
  415.                                         quit = TRUE;
  416.                                         sn->SerReadSend=FALSE;
  417.                                     }
  418.                                 }
  419.                             }
  420.                         }
  421.                         if (BreakBitMask & result)
  422.                             quit = TRUE;
  423.                     } // while
  424.                 } // sn = cport->network.networkdata
  425.             } // networktype
  426.         } // isopen
  427.     } // cport
  428.     return result;
  429. } // void ()
  430.  
  431.  
  432. void SN_HangingUP()
  433. {
  434.     struct    PortData            *cport            = (PortData *)FindTask(NULL)->tc_UserData;
  435.     char                            SerWriteFinish    = FALSE;
  436.     ULONG                         signals            = (1<<cport->TimePort->mp_SigBit);
  437.     struct    SerialNetwork     *sn;
  438.     ULONG                         result            = 0;
  439.  
  440.     if ((cport = (PortData *)FindTask(NULL)->tc_UserData))
  441.     {
  442.         if (cport->network.isopen)
  443.         {
  444.             if (cport->network.networktype == NETWORKTYPE_SERIAL)
  445.             {
  446.                 if ((sn = cport->network.networkdata))
  447.                 {
  448.                     SN_CheckNetworkStatus();
  449.                     cport->network.isopen=FALSE;
  450.                     if (!(CheckIO((IORequest *)sn->SerWrite)))
  451.                     {            
  452.                         AbortIO((IORequest *)sn->SerWrite);
  453.                         WaitIO((IORequest *)sn->SerWrite);
  454.                     }
  455.  
  456.                     /* clearing serial buffer */
  457.  
  458.                     AbortIO((IORequest *)sn->SerRead);
  459.                     WaitIO((IORequest *)sn->SerRead);
  460.                     sn->SerRead->IOSer.io_Command    =    CMD_READ;
  461.                     sn->SerRead->IOSer.io_Data        =    cport->network.ReadBuf;
  462.                     sn->SerRead->IOSer.io_Length    =    1;
  463.                     while(CheckIO((IORequest *)sn->SerRead))
  464.                     {
  465.                         WaitIO((IORequest *)sn->SerRead);
  466.                         SendIO((IORequest *)sn->SerRead);
  467.                     }
  468.     
  469.                     if (!(CheckIO((IORequest *)sn->SerRead)))
  470.                     {
  471.                         AbortIO((IORequest *)sn->SerRead);
  472.                         WaitIO((IORequest *)sn->SerRead);
  473.                     }
  474.  
  475.                     CloseDevice((IORequest *)sn->SerWrite); /* Close device for hangup */
  476.     
  477.                     Delay(5);
  478.     
  479.                     if (!cport->ProgramClose)
  480.                     {
  481.                         if (OpenDevice(cport->clientconfig.SerialData.Device_Name,cport->clientconfig.SerialData.Unit,(IORequest *)sn->SerWrite, 0))
  482.                         {
  483.                             ioprintf("can't open serial.device!\n");
  484.                         }
  485.                         else
  486.                         {
  487.                             sn->SerWrite->io_RBufLen=20;    // Größe des Eingangspuffers; ein Vielfaches von 64 Bytes
  488.                             sn->SerWrite->io_Baud=cport->clientconfig.SerialData.OnlineBaud;
  489.                             sn->SerWrite->io_BrkTime=100;  // Dauer des Unterbrechungssignals in Microsekunden.
  490.                             sn->SerWrite->io_ReadLen=cport->clientconfig.SerialData.DataBits;;
  491.                             sn->SerWrite->io_WriteLen=cport->clientconfig.SerialData.DataBits;
  492.                             sn->SerWrite->io_StopBits=cport->clientconfig.SerialData.StopBits;
  493.                             sn->SerWrite->io_SerFlags=SERF_XDISABLED|SERF_7WIRE;
  494.                             sn->SerWrite->IOSer.io_Flags = IOF_QUICK;
  495.                             sn->SerWrite->IOSer.io_Command = SDCMD_SETPARAMS;
  496.                             DoIO((IORequest *)sn->SerWrite);
  497.  
  498.                             SN_Send("ATZ\n",4);
  499.         //                    DoIO((IORequest *)sn->SerWrite);
  500.  
  501.                             *sn->SerRead = *sn->SerWrite;
  502.                             sn->SerRead->IOSer.io_Message.mn_ReplyPort=sn->SerReadPort;    // change correct port address
  503.  
  504.                             *sn->SerQuery = *sn->SerWrite;
  505.                             sn->SerQuery->IOSer.io_Message.mn_ReplyPort=sn->SerQueryPort;
  506.  
  507.                             sn->SerQuery->IOSer.io_Command = SDCMD_QUERY;
  508.                             sn->SerQuery->IOSer.io_Data     = (APTR)cport->network.ReadBuf;
  509.                             sn->SerQuery->IOSer.io_Length  = 0;
  510.  
  511.                             sn->SerRead->IOSer.io_Command  = CMD_READ;
  512.                             sn->SerRead->IOSer.io_Data      = (APTR)cport->network.ReadBuf;
  513.                             sn->SerRead->IOSer.io_Length     = 1;
  514.  
  515.         //                    SendIO((IORequest *)sn->SerRead);
  516.                             sn->SerReadSend=FALSE;
  517.  
  518.                             cport->network.isopen=TRUE;
  519.                         }
  520.                     }
  521.                 }
  522.             }
  523.         }
  524.     }
  525. }
  526.  
  527. void SN_WaitConnect()
  528. {
  529.     char                             cp[20];
  530.     char                             buffer[200];
  531.     WORD                             counter            = 0;
  532.     ULONG                         ulong;
  533.     struct    PortData            *cport            = (PortData *)FindTask(NULL)->tc_UserData;
  534.     struct    SerialNetwork     *sn;
  535.  
  536.     if ((cport = (PortData *)FindTask(NULL)->tc_UserData))
  537.     {
  538.         if (cport->network.isopen)
  539.         {
  540.             if (cport->network.networktype == NETWORKTYPE_SERIAL)
  541.             {
  542.                 if ((sn = cport->network.networkdata))
  543.                 {
  544.                     cport->PortStatus         = PORT_STATUS_WAITCALL;
  545.                     cport->network.online = FALSE;
  546.                     cport->connect_seq     = TRUE;
  547.                     cport->network.can_write = FALSE;
  548.                     cport->network.can_read  = FALSE;
  549.  
  550.                     ClearMemQuick(buffer,200);
  551.         
  552.                     AbortIO((IORequest *)sn->SerWrite);
  553.                     WaitIO((IORequest *)sn->SerWrite);
  554.  
  555.                     AbortIO((IORequest *)sn->SerRead);
  556.                     WaitIO((IORequest *)sn->SerRead);
  557.  
  558.                     sn->SerReadSend=FALSE;
  559.  
  560.                     while(CheckIO((IORequest *)sn->SerRead))
  561.                     {
  562.                         WaitIO((IORequest *)sn->SerRead);
  563.                         sn->SerRead->IOSer.io_Command    =    CMD_READ;
  564.                         sn->SerRead->IOSer.io_Data        =    cport->network.ReadBuf;
  565.                         sn->SerRead->IOSer.io_Length    =    1;
  566.                         SendIO((IORequest *)sn->SerRead);
  567.                     }
  568.  
  569.                     while (cport->connect_seq && !cport->ProgramClose)
  570.                     {
  571.                         SN_Recv(cp,1,0);
  572.                         if (*cp)
  573.                         {
  574.                             Writeio(cp,1);
  575.                             if (*cp==10|*cp==13|counter>150)
  576.                             {
  577.                                 if (counter)
  578.                                 {
  579.                                     if (strstr(buffer,"RING"))
  580.                                     {
  581.                                         Writeio("found RING\n",-1);
  582.                                         if (CheckIO((IORequest *)sn->SerWrite))
  583.                                         {
  584.                                             AbortIO((IORequest *)sn->SerWrite);
  585.                                             WaitIO((IORequest *)sn->SerWrite);
  586.                                         }
  587.                                         SN_Send("ATA\r",4);
  588.                                     }
  589.                                     if (strstr(buffer,"CID"))
  590.                                     {
  591.                                         Writeio("found CID:",-1);
  592.                                         Writeio(&buffer[6],-1);
  593. //                                        strncpy(cport->whostring,connect_string+6,30);
  594.                                         SendMsg(cport->MainPort,cport,0,MSG_PORT_CID,NULL);
  595.                                     }
  596.                                     if (strstr(buffer,"CONNECT"))
  597.                                     {
  598.                                         cport->PortStatus        = PORT_STATUS_CONNECT;
  599.                                         StrToLong(&buffer[9],(LONG *)ulong);
  600.                                         SendMsg(cport->MainPort,cport,0,MSG_PORT_CHANGE,NULL);
  601.                                         cport->connect_seq       = FALSE;
  602.                                         cport->network.online    = TRUE;
  603.                                         cport->network.can_write = TRUE;
  604.                                         cport->network.can_read  = TRUE;                                        
  605.                                     }
  606.                                 }
  607.                                 counter=0;
  608.                                 ClearMemQuick(buffer,200);
  609.                             }
  610.                             else
  611.                             {
  612.                                 buffer[counter]=*cp;
  613.                                 counter++;
  614.                             }
  615.                         }
  616.                     }
  617.                 }
  618.                 else
  619.                 {
  620.                     cport->connect_seq       = FALSE;
  621.                     cport->network.online    = TRUE;
  622.                     cport->network.can_write = FALSE;
  623.                     cport->network.can_read  = FALSE;                                        
  624.                 }
  625.             }
  626.             else
  627.             {
  628.                 cport->connect_seq       = FALSE;
  629.                 cport->network.online    = TRUE;
  630.                 cport->network.can_write = FALSE;
  631.                 cport->network.can_read  = FALSE;                                        
  632.             }
  633.         }
  634.         else
  635.         {
  636.             cport->connect_seq       = FALSE;
  637.             cport->network.online    = TRUE;
  638.             cport->network.can_write = FALSE;
  639.             cport->network.can_read  = FALSE;                                        
  640.         }
  641.     }
  642.     else
  643.     {
  644.         cport->connect_seq       = FALSE;
  645.         cport->network.online    = TRUE;
  646.         cport->network.can_write = FALSE;
  647.         cport->network.can_read  = FALSE;                                        
  648.     }
  649. }
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.